﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/WithoutPermBasic.Master" AutoEventWireup="true" CodeBehind="GeneralAssingGas.aspx.cs" Inherits="PMS.UI.PM.GeneralAssingGas" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        var BarCode = com.get.BarCode;
        var Id;
        $(function () {

            //由于配气经常出现问题，因此暂时关闭该功能
            /*
            //回车事件
            document.onkeydown = function (event) {
                var e = event || window.event;
                if (e.keyCode == 13 && e.ctrlKey) {
                    funcCompleteGas();
                }
                else {
                    if (e && e.keyCode == 13) { //回车键的键值为13
                        funcSave();
                    }
                }
            };
            */

            var height = $("#divTotal").height();
            var content = parseFloat(height) - 60;
            $("#NotInflated").css("height", content);
            $("#SweepCode").focus();

            //Jquery监听扫码枪回车事件
            $("#SweepCode").keyup(function (event) {
                if (event.keyCode == 13) {
                    var code = $(this).val();
                    code = code.replace(/\n/g, "")
                    $(this).val("");
                    BarCode = code;
                    LoadTableByBarCode(code);
                }
            });

            if (BarCode != null) {
                $("#imgBarcode").JsBarcode(BarCode);
                LoadTableByBarCode(BarCode);
            }
        });

    </script>
    <script type="text/javascript">

        function LoadTableByBarCode(barCode) {
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "/Logic/PM/BottleProductionAjax.aspx?method=GetBottleProductionById",
                data: { 'BarCode': barCode },
                success: function (data) {
                    $("#form1").form("load", data);
                    $("#BarCode").val(barCode);
                    $("#lblBarCode").html(barCode);
                    $("#lblCustomer").html(data.CustomerName);
                    $("#lblTechParams").html(data.TechParams);
                    Id = data.ID;

                }
            });

            //加载充气列表
            $("#NotInflated").datagrid({
                url: '/Logic/PM/BottleProductionAjax.aspx?method=GetNotInflatedList',
                queryParams: { 'BarCode': barCode },
                loadMsg: '数据加载中请稍后……',
                idField: "ID",
                singleSelect: true,
                columns: [[
                    {
                        field: 'ck', checkbox: true, width: 30
                    },

                    {
                        field: 'GasChiName', title: '气体名称', align: "center", width: 80
                    },
                       {
                           field: 'GasEngName', title: '分子式', align: "center", width: 80
                       },
                   {
                       field: 'Concentration', title: '浓度', align: "center", width: 80, formatter: function (value, row, index) {

                           if (row.IsComplete == "1") {

                               return "<input id='Concentration' name='Concentration'  disabled='disabled'   value='" + value + "'  style='width:60px' />%";
                           }
                           else {
                               return "<input id='Concentration' name='Concentration'  value='" + value + "'  style='width:60px' />%";
                           }

                       }
                   },

                  {
                      field: 'TotalWeight', title: '总重', align: "center", width: 80, formatter: function (value, row, index) {


                          if (row.IsComplete == "1") {
                              return "<input id='TotalWeight' name='TotalWeight'  disabled='disabled'   value='" + value + "'  style='width:70px' />";

                          }
                          else {
                              return "<input id='TotalWeight' name='TotalWeight'  value='" + value + "'  style='width:70px' />";
                          }



                      }
                  },
                  {
                      field: 'SingleWeight', title: '样气质量', align: "center", width: 80, formatter: function (value, row, index) {



                          if (row.IsComplete == "1") {

                              return "<input id='SingleWeight' name='SingleWeight' disabled='disabled'   value='" + value + "'  style='width:70px' />";


                          }
                          else {
                              return "<input id='SingleWeight' name='SingleWeight'  value='" + value + "'  style='width:70px' />";

                          }

                      }
                  },
                {
                    field: 'CalculateGasWeight', title: '分子量', align: "center", width: 100, formatter: function (value, row, index) {
                        if (row.IsComplete == "1") {
                            return "<input id='CalculateGasWeight' name='CalculateGasWeight' disabled='disabled'  value='" + value + "'  style='width:80px' />";
                        }
                        else {
                            return "<input id='CalculateGasWeight' name='CalculateGasWeight'  value='" + value + "'  style='width:80px' />";

                        }
                    }
                },
                {
                    field: 'SampleVolume', title: '样气量', align: "center", width: 80, formatter: function (value, row, index) {


                        if (row.IsComplete == "1") {



                            return "<input id='SampleVolume' name='SampleVolume' disabled='disabled'  value='" + value + "'  style='width:70px' />";


                        }
                        else {
                            return "<input id='SampleVolume' name='SampleVolume'  value='" + value + "'  style='width:70px' />";

                        }



                    }
                },
                {
                    field: 'BudgetConcentration', title: '预算浓度', align: "center", formatter: function (value, row, index) {

                        if (row.IsComplete == "1") {
                            return "<input id='BudgetConcentration' name='BudgetConcentration' disabled='disabled'  value='" + value + "' readonly='readonly'  style='width:60px' />%";
                        }
                        else {
                            return "<input id='BudgetConcentration' name='BudgetConcentration'  value='" + value + "'   style='width:60px' />%";
                        }


                    }
                },
                {
                    field: 'BudgetWeight', title: '预算克数', align: "center", width: 80, formatter: function (value, row, index) {
                        if (row.IsComplete == "1") {
                            return "<input id='BudgetWeight' name='BudgetWeight' disabled='disabled'  value='" + value + "' readonly='readonly'  style='width:70px' />";
                        }
                        else {
                            return "<input id='BudgetWeight' name='BudgetWeight'  value='" + value + "' readonly='readonly'  style='width:70px' />";
                        }
                    }
                },
                {
                    field: 'OneConcentration', title: '一次气浓度', align: "center", width: 80, formatter: function (value, row, index) {
                        if (row.IsComplete == "1") {
                            return "<input id='OneConcentration' name='OneConcentration' disabled='disabled'  value='" + value + "'  style='width:50px' />%";
                        }
                        else {
                            return "<input id='OneConcentration' name='OneConcentration'  value='" + value + "'  style='width:50px' />%";
                        }

                    }
                },
                 {
                     field: 'OneBottleCode', title: '一次气瓶号', align: "center", width: 100, formatter: function (value, row, index) {
                         if (value == null) value = '';
                         if (row.IsComplete == "1") {
                             return "<input id='OneBottleCode' name='OneBottleCode' disabled='disabled'  value='" + value + "'  style='width:90px' />";
                         }
                         else {
                             return "<input id='OneBottleCode' name='OneBottleCode'  value='" + value + "'  style='width:90px' />";
                         }

                     }
                 },
                {
                    field: 'BudgetPressure', title: '预算压力', align: "center", width: 80, formatter: function (value, row, index) {

                        if (row.IsComplete == "1") {

                            return "<input id='BudgetPressure' name='BudgetPressure' disabled='disabled'   value='" + value + "'  readonly='readonly'   style='width:70px' />";
                        }
                        else {
                            return "<input id='BudgetPressure' name='BudgetPressure'  value='" + value + "'  readonly='readonly'   style='width:70px' />";
                        }
                    }
                },
                {
                    field: 'IsBottom', title: '是否底气', align: "center", formatter: function (value, row, index) {
                        if (value == "0") {
                            return "否";
                        }
                        else {
                            return "是";
                        }
                    }
                },
                {
                    field: 'IsComplete', title: '是否完成', align: "center", formatter: function (value, row, index) {
                        if (value == "0") {
                            return "未开始";
                        }
                        else if (value == "1") {
                            return "已完成";
                        }

                    }
                },
                           {
                               field: 'QuotationNote', title: '备注', align: "center"
                           },

                ]],
                singleSelect: true,
                striped: true
            })

        }

        function funcSetBottleGas() {

            var row = $('#NotInflated').datagrid('getSelected');
            if (row != null) {
                com.ajax({
                    url: '/Logic/PM/BottleProductionAjax.aspx?method=SetBottleGas',
                    data: { GasId: row.ID },
                    success: function (data) {
                        com.message(data.state, data.msg, function () { LoadTableByBarCode(BarCode); })
                    }
                });
            }
            else {
                com.message("information", "请选中一行");
            }
        }

        function funcSave() {
            var data = GetFormData();
            var arr = GetTableData();
            var detail = JSON.stringify(arr);
            data.Detail = detail;
            com.ajax({
                data: data,
                url: "/Logic/PM/BottleProductionAjax.aspx?method=SaveGeneralAssingGas",
                success: function (data) {
                    com.message(data.state, data.msg, function () { LoadTableByBarCode(BarCode); })
                }
            })
        }



        function funcSetFirstGas() {
            //查找首次充气气体
            var row = $('#NotInflated').datagrid('getSelected');
            if (row == null) {
                com.message("information", "请选择一行作为首次充气气体！");
            }
            else {
                var firstGasId = row.ID;
                var data = GetFormData();
                var arr = GetTableData();
                var detail = JSON.stringify(arr);
                data.Detail = detail;
                data.firstGasId = firstGasId;
                com.ajax({
                    data: data,
                    url: "/Logic/PM/BottleProductionAjax.aspx?method=SetFirstGas",
                    success: function (data) {
                        com.message(data.state, data.msg, function () { LoadTableByBarCode(BarCode); })
                    }
                })
            }
        }

        function funcReInputGas() {
            var row = $('#NotInflated').datagrid('getSelected');
            if (row == null) {
                com.message("information", "请选择一行！");
            }
            else {
                com.ajax({
                    data: row,
                    url: "/Logic/PM/BottleProductionAjax.aspx?method=ReInputGas",
                    success: function (data) {
                        com.message(data.state, data.msg, function () {
                            $("#NotInflated").datagrid("unselectAll");
                            $("#NotInflated").datagrid("reload");
                        })
                    }
                })
            }

        }

        function funcCompleteGas() {
            //查找首次充气气体
            var row = $('#NotInflated').datagrid('getSelected');
            if (row == null) {
                com.message("information", "请选择一条数据！");
                return;
            }
            else if (row.IsComplete == "1") {
                com.message("information", "请勿重复充气！");
                return;
            }
            else {
                var data = GetFormData();
                var currentIndex = $("#NotInflated").datagrid("getRowIndex", row);
                var currentRowArray = new Array();
                var currentRow = GetRowByRowIndex(currentIndex);
                currentRowArray.push(currentRow);
                if (!(currentRow.TotalWeight > data.EmptyBottleWeight || (currentRow.SingleWeight != ""&&currentRow.SingleWeight!=0))) {
                    com.message("information", "请检查当前气体总重是否大于空瓶重量！");
                    return;
                }
                else if (currentRow.OneConcentration == "" || currentRow.OneConcentration == 0 || currentRow.BudgetPressure == "" || currentRow.BudgetPressure == 0) {
                    com.message("information", "一次气浓度或预算压力不能为0，请填写预算浓度后保存！");
                    return;
                }
                else {
                    data.currentRowArray = JSON.stringify(currentRowArray);
                    var arr = GetTableData();
                    var detail = JSON.stringify(arr);
                    data.Detail = detail;
                    com.ajax({
                        data: data,
                        url: "/Logic/PM/BottleProductionAjax.aspx?method=CompleteGas",
                        success: function (returnData) {
                            com.message(returnData.state, returnData.msg, function () {

                                LoadTableByBarCode(BarCode);
                            })
                        }
                    })
                }
            }
        }

        function funcPrint() {
            JsBarcode("#imgBarcode", BarCode, {
                width: 2.6,//设置条之间的宽度
                height: 87,//高度
                displayValue: false,//是否在条形码下方显示文字
            });

            $("#divPrint").show();


            $("#divPrint").print({
                globalStyles: true,//是否包含父文档的样式，默认为true
                mediaPrint: false,//是否包含media='print'的链接标签。会被globalStyles选项覆盖，默认为false
                stylesheet: null,//外部样式表的URL地址，默认为null

                noPrintSelector: ".no-print",//不想打印的元素的jQuery选择器，默认为".no-print"
                iframe: true,//是否使用一个iframe来替代打印表单的弹出窗口，true为在本页面进行打印，false就是说新开一个页面打印，默认为true
                append: null,//将内容添加到打印内容的后面
                prepend: null,//将内容添加到打印内容的前面，可以用来作为要打印内容
                deferred:
             $.Deferred(

                    )//回调函数
            });
            //   $("#divPrint").printArea();
            $("#divPrint").hide();
        }

        //跳过计算
        function funcSkipCalc() {
            var data = GetFormData();
            var arr = GetTableData();
            var detail = JSON.stringify(arr);
            data.Detail = detail;
            var mainID = data.MainId;
            com.ajax({
                data: data,
                url: "/Logic/PM/BottleProductionAjax.aspx?method=SkipCalc",
                success: function (data) {
                    com.message(data.state, data.msg)
                    // $("#NotInflated").datagrid("reload"); 
                    var url = "/UI/PM/BottleAnalyseRes.aspx?action=edit&ID=" + mainID;
                    top.wrapper.addTab("编辑分析结果", url)
                }
            })
        }

        //跳过计算与分析，直接打印
        function funcSkipCalcAna() {
            var data = GetFormData();
            var arr = GetTableData();
            var detail = JSON.stringify(arr);
            data.Detail = detail;
            var mainID = data.MainId;
            com.ajax({
                data: data,
                url: "/Logic/PM/BottleProductionAjax.aspx?method=SkipCalcAna",
                success: function (data) {
                    com.message(data.state, data.msg)
                    var url = "/UI/PM/BottleAnalyseRes.aspx?action=edit&ID=" + mainID;
                    top.wrapper.addTab("编辑分析结果", url)
                }
            })
        }

        //公用方法
        function GetFormData() {
            var data = { EmptyBottleWeight: $("#EmptyBottleWeight").val(), BudgetPressure: $("#BudgetPressure").val(), TotalNum: $("#TotalNum").val(), MainId: Id };
            return data;
        }
        function GetTableData() {
            var rows = $("#NotInflated").datagrid("getRows");
            var arr = new Array();
            for (var i = 0; i < rows.length; i++) {
                var $tr = $("#divTable tr:eq(" + parseInt(i + 1) + ")");
                rows[i]["Concentration"] = $tr.find("#Concentration").val();
                rows[i]["TotalWeight"] = $tr.find("#TotalWeight").val();
                rows[i]["SingleWeight"] = $tr.find("#SingleWeight").val();
                rows[i]["SampleVolume"] = $tr.find("#SampleVolume").val();
                rows[i]["BudgetWeight"] = $tr.find("#BudgetWeight").val();
                rows[i]["OneConcentration"] = $tr.find("#OneConcentration").val();
                rows[i]["BudgetPressure"] = $tr.find("#BudgetPressure").val();
                rows[i]["BudgetConcentration"] = $tr.find("#BudgetConcentration").val();
                rows[i]["OneBottleCode"] = $tr.find("#OneBottleCode").val();
                rows[i]["CalculateGasWeight"] = $tr.find("#CalculateGasWeight").val();
                if (rows[i]["BudgetConcentration"] == null || rows[i]["BudgetConcentration"] == "") {
                    rows[i]["BudgetConcentration"] = 0;
                }
                arr.push(rows[i]);
            }
            return arr;
        }


        function GetRowByRowIndex(RowIndex) {
            var rows = $("#NotInflated").datagrid("getRows");
            var $tr = $("#divTable tr:eq(" + parseInt(RowIndex + 1) + ")");
            rows[RowIndex]["Concentration"] = $tr.find("#Concentration").val();
            rows[RowIndex]["TotalWeight"] = $tr.find("#TotalWeight").val();
            rows[RowIndex]["SingleWeight"] = $tr.find("#SingleWeight").val();
            rows[RowIndex]["SampleVolume"] = $tr.find("#SampleVolume").val();
            rows[RowIndex]["BudgetWeight"] = $tr.find("#BudgetWeight").val();
            rows[RowIndex]["OneConcentration"] = $tr.find("#OneConcentration").val();
            rows[RowIndex]["BudgetPressure"] = $tr.find("#BudgetPressure").val();
            rows[RowIndex]["BudgetConcentration"] = $tr.find("#BudgetConcentration").val();
            rows[RowIndex]["OneBottleCode"] = $tr.find("#OneBottleCode").val();
            return rows[RowIndex];
        }


    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceToorbar" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">

    <div style="height: 100%; overflow: auto">
        <div id="master" class="container_16" style="height: auto;">
            <form id="form1">
                <div class="grid_12 val" style="height: 100px">
                    <textarea id="SweepCode" name="Note" style="width: 900px; height: 80px" placeholder="该区域是扫码区域，需要获取鼠标焦点，即可扫码"></textarea>
                </div>
                <div class="clear"></div>
                <div id="title" class="grid_16" style="text-align: center">
                    <h1>配气记录表</h1>
                </div>
                <div class="clear"></div>

                <div class="grid_4 lbl" style="text-align: right;">
                    流水号: 
                    <input type="text" id="BarCode" name="BarCode" disabled="disabled" />
                </div>


                <div class="grid_4 lbl" style="text-align: right;">
                    瓶号:
                    <input type="text" id="BottleCode" name="BottleCode" disabled="disabled" />
                </div>

                <div class="grid_4 lbl" style="text-align: right;">
                    使用单位: 
                    <input type="text" id="CustomerName" name="CustomerName" disabled="disabled" />
                </div>

                <div class="grid_4 lbl" style="text-align: right;">
                    订单日期:<input type="text" id="FillDate" name="FillDate" disabled="disabled" />
                </div>

                <div class="clear"></div>
                <div class="grid_4 lbl" style="text-align: right;">
                    空瓶重 :<input type="text" id="EmptyBottleWeight" name="EmptyBottleWeight" class="easyui-numberbox" data-options="min:0,precision:3" />
                </div>

                <div class="grid_4 lbl" style="text-align: right;">
                    预算压力 : 
                    <input type="text" id="BudgetPressure" name="BudgetPressure" class="easyui-numberbox" data-options="min:0,precision:2" />
                </div>

                <div class="grid_4 lbl" style="text-align: right;">
                    总量:<input type="text" id="TotalNum" name="TotalNum" class="easyui-textbox" data-options="editable:false" />
                </div>
                <div class="grid_4 lbl" style="text-align: right;">
                    预算总量:<input type="text" id="BudgetTotalNum" name="BudgetTotalNum" class="easyui-textbox" data-options="editable:false" />
                </div>
                <div class="clear"></div>


            </form>
        </div>
    </div>
    <div id="divTable" style="overflow: hidden; height: auto; width: 1200px; text-align: center; margin: 0 auto">

        <div class="easyui-toolbar" style="float: left">
            <a id="Print" href="#" iconcls="icon-printer" onclick="funcPrint()">打印条码</a>
            <a id="SkipCalc" href="#" iconcls="icon-printer" onclick="funcSkipCalc()">跳过计算</a>
            <a id="SkipCalcAna" href="#" iconcls="icon-printer" onclick="funcSkipCalcAna()">跳过计算分析</a>
            <a id="Save" href="#" iconcls="icon-save" onclick="funcSave()">保存数据</a>
            <a id="SetBottomGas" href="#" iconcls="icon-save" onclick="funcSetBottleGas()">设置底气</a>
            <%--  <a id="SetFirstGas" href="#" iconcls="icon-save" onclick="funcSetFirstGas()">首次充气</a>--%>
            <a id="CompleteGas" href="#" iconcls="icon-save" onclick="funcCompleteGas()">完成充气</a>
            <a id="ReInputGas" href="#" iconcls="icon-save" onclick="funcReInputGas()">重新充气</a>


        </div>


        <table id="NotInflated" style="width: 100%; height: auto; margin: 0 auto" title="气瓶配气"></table>
    </div>
    <div id="divPrint" style="margin-left: 2px; word-break: break-all; width: 250px; height: 20px; display: none">
        <img id="imgBarcode" /><br />
        <label id="lblBarCode" style="font-size: 20px; margin-left: 70px"></label>
        <br />
        <%--<label id="lblCustomer" style="font-size: 16px;"></label>--%>

        <label id="lblCustomer" style="font-size: 25px; font-weight: 600; height: auto; width: auto; border: hidden"></label>

        <br />
        <label id="lblTechParams" style="font-size: 25px; overflow: hidden; border: hidden; font-weight: 600; height: auto; width: auto;">
        </label>
    </div>
</asp:Content>
